import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * model 个性化单元
 * @date: 2019-12-12


 */
import { getResponse, createPagination } from 'utils/utils';
import { queryList as _queryList, queryMenuTree, createUnit as _createUnit, queryUnitDetail, modifyUnit as _modifyUnit, saveUnitField as _saveUnitField, queryRelationModels as _queryRelationModels, queryRelatedUnits as _queryRelatedUnits, deleteField as _deleteField, queryGroup as _queryGroup, createGroup as _createGroup, modifyGroup as _modifyGroup, queryGroupUnits as _queryGroupUnits, copyUnit as _copyUnit } from "../services/individuationUnitService";
export default {
  namespace: 'individuationUnit',
  state: {
    dataSource: [],
    pagination: {},
    tables: []
  },
  effects: {
    // 获取列表
    queryList: /*#__PURE__*/_regeneratorRuntime.mark(function queryList(_ref, _ref2) {
      var params, call, response, dataSource, pagination;
      return _regeneratorRuntime.wrap(function queryList$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              params = _ref.params;
              call = _ref2.call;
              _context.t0 = getResponse;
              _context.next = 5;
              return call(_queryList, params);

            case 5:
              _context.t1 = _context.sent;
              response = (0, _context.t0)(_context.t1);
              dataSource = (response || {}).content || [];
              pagination = createPagination(response || {});
              return _context.abrupt("return", {
                dataSource: dataSource,
                pagination: pagination
              });

            case 10:
            case "end":
              return _context.stop();
          }
        }
      }, queryList);
    }),
    // 获取菜单树
    fetchMenu: /*#__PURE__*/_regeneratorRuntime.mark(function fetchMenu(_ref3, _ref4) {
      var params, call, response;
      return _regeneratorRuntime.wrap(function fetchMenu$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              params = _ref3.params;
              call = _ref4.call;
              _context2.t0 = getResponse;
              _context2.next = 5;
              return call(queryMenuTree, params);

            case 5:
              _context2.t1 = _context2.sent;
              response = (0, _context2.t0)(_context2.t1);
              return _context2.abrupt("return", response);

            case 8:
            case "end":
              return _context2.stop();
          }
        }
      }, fetchMenu);
    }),
    // 创建个性化单元
    createUnit: /*#__PURE__*/_regeneratorRuntime.mark(function createUnit(_ref5, _ref6) {
      var params, call, response;
      return _regeneratorRuntime.wrap(function createUnit$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              params = _ref5.params;
              call = _ref6.call;
              _context3.t0 = getResponse;
              _context3.next = 5;
              return call(_createUnit, params);

            case 5:
              _context3.t1 = _context3.sent;
              response = (0, _context3.t0)(_context3.t1);
              return _context3.abrupt("return", response);

            case 8:
            case "end":
              return _context3.stop();
          }
        }
      }, createUnit);
    }),
    // 个性化单元详情以及字段配置
    fetchUnitDetail: /*#__PURE__*/_regeneratorRuntime.mark(function fetchUnitDetail(_ref7, _ref8) {
      var params, call, response;
      return _regeneratorRuntime.wrap(function fetchUnitDetail$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              params = _ref7.params;
              call = _ref8.call;
              _context4.t0 = getResponse;
              _context4.next = 5;
              return call(queryUnitDetail, params);

            case 5:
              _context4.t1 = _context4.sent;
              response = (0, _context4.t0)(_context4.t1);
              return _context4.abrupt("return", response);

            case 8:
            case "end":
              return _context4.stop();
          }
        }
      }, fetchUnitDetail);
    }),
    // 修改个性化单元信息
    modifyUnit: /*#__PURE__*/_regeneratorRuntime.mark(function modifyUnit(_ref9, _ref10) {
      var params, call, response;
      return _regeneratorRuntime.wrap(function modifyUnit$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              params = _ref9.params;
              call = _ref10.call;
              _context5.t0 = getResponse;
              _context5.next = 5;
              return call(_modifyUnit, params);

            case 5:
              _context5.t1 = _context5.sent;
              response = (0, _context5.t0)(_context5.t1);
              return _context5.abrupt("return", response);

            case 8:
            case "end":
              return _context5.stop();
          }
        }
      }, modifyUnit);
    }),
    // 保存个性化单元字段
    saveUnitField: /*#__PURE__*/_regeneratorRuntime.mark(function saveUnitField(_ref11, _ref12) {
      var params, call, response;
      return _regeneratorRuntime.wrap(function saveUnitField$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              params = _ref11.params;
              call = _ref12.call;
              _context6.t0 = getResponse;
              _context6.next = 5;
              return call(_saveUnitField, params);

            case 5:
              _context6.t1 = _context6.sent;
              response = (0, _context6.t0)(_context6.t1);
              return _context6.abrupt("return", response);

            case 8:
            case "end":
              return _context6.stop();
          }
        }
      }, saveUnitField);
    }),
    // 查询关联模型
    queryRelationModels: /*#__PURE__*/_regeneratorRuntime.mark(function queryRelationModels(_ref13, _ref14) {
      var params, call, response;
      return _regeneratorRuntime.wrap(function queryRelationModels$(_context7) {
        while (1) {
          switch (_context7.prev = _context7.next) {
            case 0:
              params = _ref13.params;
              call = _ref14.call;
              _context7.t0 = getResponse;
              _context7.next = 5;
              return call(_queryRelationModels, params);

            case 5:
              _context7.t1 = _context7.sent;
              response = (0, _context7.t0)(_context7.t1);
              return _context7.abrupt("return", response);

            case 8:
            case "end":
              return _context7.stop();
          }
        }
      }, queryRelationModels);
    }),
    // 删除个性化单元字段
    deleteField: /*#__PURE__*/_regeneratorRuntime.mark(function deleteField(_ref15, _ref16) {
      var params, call, response;
      return _regeneratorRuntime.wrap(function deleteField$(_context8) {
        while (1) {
          switch (_context8.prev = _context8.next) {
            case 0:
              params = _ref15.params;
              call = _ref16.call;
              _context8.t0 = getResponse;
              _context8.next = 5;
              return call(_deleteField, params);

            case 5:
              _context8.t1 = _context8.sent;
              response = (0, _context8.t0)(_context8.t1);
              return _context8.abrupt("return", response);

            case 8:
            case "end":
              return _context8.stop();
          }
        }
      }, deleteField);
    }),
    // 查询分组
    queryGroup: /*#__PURE__*/_regeneratorRuntime.mark(function queryGroup(_ref17, _ref18) {
      var params, call, response;
      return _regeneratorRuntime.wrap(function queryGroup$(_context9) {
        while (1) {
          switch (_context9.prev = _context9.next) {
            case 0:
              params = _ref17.params;
              call = _ref18.call;
              _context9.t0 = getResponse;
              _context9.next = 5;
              return call(_queryGroup, params);

            case 5:
              _context9.t1 = _context9.sent;
              response = (0, _context9.t0)(_context9.t1);
              return _context9.abrupt("return", response || []);

            case 8:
            case "end":
              return _context9.stop();
          }
        }
      }, queryGroup);
    }),
    // 创建分组
    createGroup: /*#__PURE__*/_regeneratorRuntime.mark(function createGroup(_ref19, _ref20) {
      var params, call, response;
      return _regeneratorRuntime.wrap(function createGroup$(_context10) {
        while (1) {
          switch (_context10.prev = _context10.next) {
            case 0:
              params = _ref19.params;
              call = _ref20.call;
              _context10.t0 = getResponse;
              _context10.next = 5;
              return call(_createGroup, params);

            case 5:
              _context10.t1 = _context10.sent;
              response = (0, _context10.t0)(_context10.t1);
              return _context10.abrupt("return", response || {});

            case 8:
            case "end":
              return _context10.stop();
          }
        }
      }, createGroup);
    }),
    // 修改分组
    modifyGroup: /*#__PURE__*/_regeneratorRuntime.mark(function modifyGroup(_ref21, _ref22) {
      var params, call, response;
      return _regeneratorRuntime.wrap(function modifyGroup$(_context11) {
        while (1) {
          switch (_context11.prev = _context11.next) {
            case 0:
              params = _ref21.params;
              call = _ref22.call;
              _context11.t0 = getResponse;
              _context11.next = 5;
              return call(_modifyGroup, params);

            case 5:
              _context11.t1 = _context11.sent;
              response = (0, _context11.t0)(_context11.t1);
              return _context11.abrupt("return", response || {});

            case 8:
            case "end":
              return _context11.stop();
          }
        }
      }, modifyGroup);
    }),
    // 查询分组下的所有个性化单元
    queryGroupUnits: /*#__PURE__*/_regeneratorRuntime.mark(function queryGroupUnits(_ref23, _ref24) {
      var params, call, response;
      return _regeneratorRuntime.wrap(function queryGroupUnits$(_context12) {
        while (1) {
          switch (_context12.prev = _context12.next) {
            case 0:
              params = _ref23.params;
              call = _ref24.call;
              _context12.t0 = getResponse;
              _context12.next = 5;
              return call(_queryGroupUnits, params);

            case 5:
              _context12.t1 = _context12.sent;
              response = (0, _context12.t0)(_context12.t1);
              return _context12.abrupt("return", response || []);

            case 8:
            case "end":
              return _context12.stop();
          }
        }
      }, queryGroupUnits);
    }),
    // 复制个性化单元
    copyUnit: /*#__PURE__*/_regeneratorRuntime.mark(function copyUnit(_ref25, _ref26) {
      var params, call, response;
      return _regeneratorRuntime.wrap(function copyUnit$(_context13) {
        while (1) {
          switch (_context13.prev = _context13.next) {
            case 0:
              params = _ref25.params;
              call = _ref26.call;
              _context13.t0 = getResponse;
              _context13.next = 5;
              return call(_copyUnit, params);

            case 5:
              _context13.t1 = _context13.sent;
              response = (0, _context13.t0)(_context13.t1);
              return _context13.abrupt("return", response);

            case 8:
            case "end":
              return _context13.stop();
          }
        }
      }, copyUnit);
    }),
    // 查询关联单元字段配置
    queryRelatedUnits: /*#__PURE__*/_regeneratorRuntime.mark(function queryRelatedUnits(_ref27, _ref28) {
      var payload, call;
      return _regeneratorRuntime.wrap(function queryRelatedUnits$(_context14) {
        while (1) {
          switch (_context14.prev = _context14.next) {
            case 0:
              payload = _ref27.payload;
              call = _ref28.call;
              _context14.t0 = getResponse;
              _context14.next = 5;
              return call(_queryRelatedUnits, payload);

            case 5:
              _context14.t1 = _context14.sent;
              return _context14.abrupt("return", (0, _context14.t0)(_context14.t1));

            case 7:
            case "end":
              return _context14.stop();
          }
        }
      }, queryRelatedUnits);
    })
  },
  reducers: {
    updateState: function updateState(state, _ref29) {
      var payload = _ref29.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};